﻿using System;
using System.ComponentModel.Composition;
using GalaSoft.MvvmLight.Messaging;

namespace Songhay.Wpf.WordWalkingStick
{
    using Songhay.Composition;
    using Songhay.Office2010.Word;
    using Songhay.Wpf.Mvvm.Models;
    using Songhay.Wpf.WordWalkingStick.Views;

    [Export(typeof(ICompositionMessaging))]
    public class CompositionMessaging : ICompositionMessaging
    {
        #region IMessagingContext Members

        /// <summary>
        /// Registers the Composition Messaging message receivers.
        /// </summary>
        public void RegisterMessageReceivers()
        {
                //Receive MvvmLight message:
                Messenger.Default.Register(this, new Action<GenericMessage<TransformationMessage>>(
                message =>
                {
                    var clientMessage = message.Content.InnerMessage
                        as IControlInteractionMessage<ClientView>;

                    if(clientMessage == null)
                        throw new ArgumentNullException(
                            "The message cannot be cast into useful type.");

                    clientMessage.SpecifiedView.Show();

                }));
        }

        #endregion
    }
}
